package top.hongthorn.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@ApiModel(value = "Result对象", description = "返回数据集")
public class Result<T> {
    @ApiModelProperty("状态码")
    private Integer state;

    @ApiModelProperty("返回消息")
    private String message;

    @ApiModelProperty("返回数据")
    private T data;

    public Result(Integer state, String message) {
        this.state = state;
        this.message = message;
    }


    public Result() {
    }

    public Result(Integer state, String message, T data) {
        this.state = state;
        this.message = message;
        this.data = data;
    }


    public static <T> Result<T> success(Integer state, String message, T data) {
        return new Result<T>(state, message, data);
    }


    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(200, message, data);
    }

    public static <T> Result<T> success(String message) {
        return new Result<T>(200, message);
    }

    public static <T> Result<T> success(Integer state, String message) {
        return new Result<T>(state, message);
    }


    public static <T> Result<T> error(Integer state, String message, T data) {
        return new Result<>(state, message, data);
    }


    public static <T> Result<T> error(String message, T data) {
        return new Result<>(500, message, data);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(500, message);
    }


    public static <T> Result<T> error(Integer state, String message) {
        return new Result<>(state, message);
    }

}